package com.usian.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.usian.mapper.ClassifyMapper;
import com.usian.mapper.CreateMapper;
import com.usian.mapper.HistorySearchMapper;
import com.usian.mapper.HotSearchMapper;
import com.usian.model.aiades.entity.*;
import com.usian.model.aiades.from.AiadesFrom;
import com.usian.model.aiades.from.ClassifyFrom;
import com.usian.service.AiadesService;
import com.usian.service.CreateService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/aiades/")
@CrossOrigin
public class AiadesController {

    @Resource
    private AiadesService aiadesService;
    @Resource
    private ClassifyMapper classifyMapper;
    @Resource
    private HistorySearchMapper historySearchMapper;
    @Resource
    private HotSearchMapper hotSearchMapper;
    @Resource
    CreateService createService;
    @Resource
    private CreateMapper createMapper;

    @Operation(summary = "助手模块主页展示")
    @RequestMapping("/findaiades")
    public List<AiadesShow> findaiades(@RequestBody AiadesFrom aiades){
//        查询所有
        return aiadesService.findaiades(aiades);
    }
    @Operation(summary = "助手模块主分类查询")
    @RequestMapping("/findclassify")
    public List<ClassifyShow> findclassify(){
        return classifyMapper.selectList(null);
    }
    @Operation(summary = "助手模块子分类查询")
    @RequestMapping("/findcreate")
    public List<CreateShow> findcreate(){
        return createService.findcreate();
    }

    @Operation(summary = "搜索模块历史记录查询")
    @RequestMapping("/findhistory")
    public List<HistorySearch> findhistory(){
        return historySearchMapper.selectList(null);
    }
    @Operation(summary = "搜索模块热门查询")
    @RequestMapping("/findhot")
    public List<HotSearch> findhot(){
        return hotSearchMapper.selectList(null);
    }
    @Operation(summary = "搜索模块创建查询")
    @RequestMapping("/findsearch")
    public List<AiadesShow>  findsearch(String searchText){
      List<AiadesShow>  list =aiadesService.findsearch(searchText);
        LambdaQueryWrapper<HistorySearch> qr = new LambdaQueryWrapper<>();
        qr.eq(HistorySearch::getHistoryname,searchText);
        if (historySearchMapper.selectList(qr).size()==0){
            HistorySearch historySearch = new HistorySearch();
            historySearch.setHistoryname(searchText);
            historySearchMapper.insert(historySearch);
        }
        return list;
    }

}
